package ca.skygazer.embedded.comms;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.XMPPConnection;

public class XMPP_CommsManager {
	
	private static XMPP_CommsManager INSTANCE=null;
	private XMPPConnection conn;
	private ChatManager chatmanager;
	private Chat chat;
	
	private XMPP_CommsManager(){
		connect();
	}
	
	public void connect(){
		try{
			System.out.println("Initializing XMPP connection");
			conn = new XMPPConnection("jabber.org");
			conn.connect();
			conn.login("telescopecontroller@jabber.org", "ab8ux%10*");			
			chatmanager = conn.getChatManager();
			chat = chatmanager.createChat("telescopeclient@jabber.org", new XMPP_CommsListener());
			
		} catch(Exception e){
			
		}		
	}
	
	public void disconnect(){
		conn.disconnect();
	}
	
	public static XMPP_CommsManager getInstance(){
		if(INSTANCE==null)
			INSTANCE=new XMPP_CommsManager();
		return INSTANCE;
	}
	
	public Chat getChat(){
		return chat;
	}

}
